import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main_1 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        Integer num = Integer.parseInt(br.readLine());

        String arr[] = new String[num];
        for (int i = 0; i < num; i++) {
            arr[i] = br.readLine();
        }

        int dis = 0;
        for (int i = 0; i < num; i++) {
            for (int j = num - 1; j >= 0; j--) {
                if (arr[i].equals(arr[j])) {
                    dis = (j - i) > dis ? (j - i) : dis;
                }
            }

        }
        if (dis == 0) {
            System.out.println(-1);
        } else {
            System.out.println(dis);
        }
    }
}
